package com.zy.explore.generator.infrastructure.core.brick.parent;

import com.zy.explore.generator.infrastructure.core.brick.child.GenerationJpaEntity;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationJpaRepository;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationMpMybatisDao;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationMpMybatisEntity;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationMpMybatisXml;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationTkMybatisDao;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationTkMybatisEntity;
import com.zy.explore.generator.infrastructure.core.brick.child.GenerationTkMybatisXml;
import com.zy.explore.generator.infrastructure.core.frm.BrickInfoFrm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * description 生成JPA持久层
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2021年06月05日 17:57
 */
@Slf4j
@Service
public class GenerationPersistenceLayer {

    @Resource
    private GenerationJpaRepository generationJpaRepository;
    @Resource
    private GenerationJpaEntity generationJpaEntity;

    @Resource
    private GenerationTkMybatisDao generationTkMybatisDao;
    @Resource
    private GenerationTkMybatisEntity generationTkMybatisEntity;
    @Resource
    private GenerationTkMybatisXml generationTkMybatisXml;

    @Resource
    private GenerationMpMybatisDao generationMpMybatisDao;
    @Resource
    private GenerationMpMybatisEntity generationMpMybatisEntity;
    @Resource
    private GenerationMpMybatisXml generationMpMybatisXml;

    /**
     * 方法说明：生成持久层(领域层)代码
     *
     * @param frm 纳
     * @throws Exception 异常
     */
    public void doGeneration(BrickInfoFrm frm) throws Exception {
        if (frm.getUseJpa()) {
            generationJpaRepository.doGeneration(frm);
            generationJpaEntity.doGeneration(frm);
            log.info("创建JPA持久层完成");
        }
        if (frm.getUseTkMybatis()) {
            generationTkMybatisDao.doGeneration(frm);
            generationTkMybatisEntity.doGeneration(frm);
            generationTkMybatisXml.doGeneration(frm);
            log.info("创建TkMybatis持久层完成");
        }
        if (frm.getUseMybatisPlus()) {
            generationMpMybatisDao.doGeneration(frm);
            generationMpMybatisEntity.doGeneration(frm);
            generationMpMybatisXml.doGeneration(frm);
            log.info("创建MpMybatis持久层完成");
        }
        log.info("创建持久层完成");
    }

}
